//
//  WXPOrderChannelView.m
//  MexicoLoan
//
//  Created by WXP on 2025/3/3.
//
//

#import "WXPOrderChannelView.h"

@interface WXPOrderChannelView ()

@end

@implementation WXPOrderChannelView

#pragma mark - lazy
- (UIView *)viewBack
{
    if (_viewBack == nil) {
        _viewBack = [UIView  new];
        _viewBack.backgroundColor = COLOR_WHITE;
        _viewBack.widthHeight = XY(SCREEN_WIDTH-LEFT_MARDIN*2, Ratio(56));
        [GlobalMethod setRoundView:_viewBack color:[UIColor clearColor] numRound:16 width:0];
    }
    return  _viewBack;
}
- (UIButton *)btnLeft
{
    if (_btnLeft == nil) {
        _btnLeft = [UIButton  new];
        _btnLeft.widthHeight = XY((self.viewBack.width-10-10)/2, self.viewBack.height-12);
        [GlobalMethod setRoundView:_btnLeft color:[UIColor clearColor] numRound:16 width:0];
        _btnLeft.leftCenterY = XY(10, self.viewBack.height/2);
        [_btnLeft setTitle:@"Pedidos actuales" forState:UIControlStateNormal];
        [_btnLeft setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        _btnLeft.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        _btnLeft.backgroundColor = COLOR_PRIMARY;
        WEAKSELF
        [_btnLeft setNoRepeatActionWithInterval:1 action:^(UIButton * _Nonnull button) {
            [weakSelf resetChannelBtn:true];
        }];
    }
    return  _btnLeft;
}
- (UIButton *)btnRight
{
    if (_btnRight == nil) {
        _btnRight = [UIButton  new];
        _btnRight.widthHeight = self.btnLeft.widthHeight;
        [GlobalMethod setRoundView:_btnRight color:[UIColor clearColor] numRound:16 width:0];
        _btnRight.leftCenterY = XY(self.btnLeft.right, self.viewBack.height/2);
        [_btnRight setTitle:@"Pedidos históricos" forState:UIControlStateNormal];
        [_btnRight setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        _btnRight.titleLabel.font = [UIFont systemFontOfSize:14];
        _btnRight.backgroundColor = COLOR_WHITE;
        WEAKSELF
        [_btnRight setNoRepeatActionWithInterval:1 action:^(UIButton * _Nonnull button) {
            [weakSelf resetChannelBtn:false];
        }];
    }
    return  _btnRight;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];//背景色
        self.width = SCREEN_WIDTH;//默认宽度
        [self addSubView];//添加子视图
    }
    return self;
}

//添加subview
- (void)addSubView{
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.btnLeft];
    [self.viewBack addSubview:self.btnRight];
    self.viewBack.centerXTop = XY(self.width/2, 0);
    self.height = self.viewBack.bottom;
}

- (void)resetChannelBtn:(BOOL)isLeft{
    [NSObject clickFeedback];
    if(isLeft){
        [self.btnLeft addClickAnimate];
    }else{
        [self.btnRight addClickAnimate];
    }
    self.btnLeft.titleLabel.font = isLeft ? [UIFont boldSystemFontOfSize:14] : [UIFont systemFontOfSize:14];
    self.btnLeft.backgroundColor = isLeft ? COLOR_PRIMARY : COLOR_WHITE;
    self.btnRight.titleLabel.font = isLeft ? [UIFont systemFontOfSize:14] : [UIFont boldSystemFontOfSize:14];
    self.btnRight.backgroundColor = isLeft ? COLOR_WHITE : COLOR_PRIMARY;
    if(self.blockChannelSwitch){
        self.blockChannelSwitch(isLeft == true ? @"1" : @"2");
    }
}

@end
